package com.easy.controller;


import com.easy.bean.Room;
import com.easy.service.RoomService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.apache.logging.log4j.message.StringFormattedMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("room")
public class RoomController {
    @Autowired
    RoomService roomService;

    @PostMapping
    public Result add(@RequestBody Room room) {
        Object obj = roomService.add(room);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Room room) {
        Object obj = roomService.edit(room);
        return Result.success(obj);
    }

    @DeleteMapping("{roomName}")
    public Result del(@PathVariable(name = "roomName")String roomName) {
        Object obj = roomService.del(roomName);
        return Result.success(obj);
    }

    @GetMapping("{roomName}")
    public Result one(@PathVariable(name = "roomName") String roomName) {
        Object obj = roomService.one(roomName);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Room room) {
        Object obj = roomService.all(room);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Room room) {
        roomService.page(page, room);
        return Result.success(page);
    }
}